package com.wxx.main;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.springframework.util.StringUtils;

import com.wxx.model.Msg;
import com.wxx.model.MsgKey;

public class CatcheMain {

	public static void main(String[] args) throws SQLException {
		Context ctx = null;
		DataSource dataSource;
		Connection conn = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		
		Map<MsgKey, Msg> map = new HashMap<MsgKey, Msg>();
		try {
			ctx = new InitialContext();
			dataSource = (DataSource) ctx
					.lookup("java:/comp/env/jdbc/sapx86DS");
			conn = dataSource.getConnection();
			String sq1 = "select id, `key`, client_key, tran_id, system, sys_id, `value`, old_value, is_wrap from b_msg";
			
			pstat = conn.prepareStatement(sq1);
			rs = pstat.executeQuery();
			while (rs.next()) {
				MsgKey key = new MsgKey();
				key.setKey(rs.getString("key"));
				key.setClientKey(rs.getString("client_key"));
				key.setTranId(rs.getLong("tran_id"));

				Msg msg = new Msg();
				msg.setId(rs.getLong("id"));
				msg.setKey(rs.getString("key"));
				msg.setClientKey(StringUtils.isEmpty(rs.getString("client_key")) ? rs
						.getString("client_key") : "0");
				msg.setTranId(rs.getLong("tran_id"));
				msg.setSystem(rs.getString("system"));
				msg.setSysId(StringUtils.isEmpty(rs.getString("sys_id")) ? rs
						.getString("sys_id") : "");
				msg.setValue(rs.getString("value"));
				msg.setOldValue(rs.getString("old_value"));
				msg.setWrap(rs.getBoolean("is_wrap"));
				map.put(key, msg);
			}
		}
		catch(Exception e)
		{
			
		}
		finally
		{
			rs.close();
			try {
				ctx.close();
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			pstat.close();
			conn.close();
		}
		
		
	}
}
